function changeColor(e){
	x = document.querySelectorAll(".left_ul a")
	for (i=0;i<x.length;i++){
		x[i].style.color="#FFFFFF"
	}
	e.style.color="#409EFF"
}
function changeColor_1(e){
	x = document.querySelectorAll(".right_ul a")
	for (i=0;i<x.length;i++){
		x[i].style.color="#FFFFFF"
	}
	e.style.color="#409EFF"
	topic = e.getAttribute("date-index");
	var url = "/News/ajax?source="+mediaType.toString()+"&sentiment="+sentiment.toString()+"&time="+time_down_up.toString()+"&topic="+topic.toString()
	loadArticle(url);
	console.log(url);
	
}
var monitor = 0
function fold(){
	if (monitor) {
		document.getElementsByClassName("right_ul")[0].style.display="none";
		monitor=0;
	}
	else{
		document.getElementsByClassName("right_ul")[0].style.display="block";
		monitor=1;
	}
}
// function changeColor_u(e,name){
// 	x=document.querySelectorAll(name)
// 	for (i=0;i<x.length;i++){
// 		x[i].style.color="#FFFFFF";
// 	}
// 	e.style.color="#F56C6C"
// }

var mediaType=0;
var sentiment=0;
var time_down_up=0;
var topic=0;

function changeColor_u(e){
	x=document.querySelectorAll(".mediaType a");
	for (i=0;i<x.length;i++){
		x[i].style.color = "#303133";
	}
	e.style.color = "#F56C6C";
	mediaType = e.getAttribute("date-index");
	var url = "/News/ajax?source="+mediaType.toString()+"&sentiment="+sentiment.toString()+"&time="+time_down_up.toString()+"&topic="+topic.toString();
	loadArticle(url);
	console.log(url);
	// console.log(e.getAttribute("date-index"));
}
function changeColor_sentiment(e){
	x=document.querySelectorAll(".sentiment a");
	for (i=0;i<x.length;i++){
		x[i].style.color = "#303133";
	}
	e.style.color = "#F56C6C";
	sentiment = e.getAttribute("date-index");
	var url = "/News/ajax?source="+mediaType.toString()+"&sentiment="+sentiment.toString()+"&time="+time_down_up.toString()+"&topic="+topic.toString();
	loadArticle(url);
	console.log(url);
}
function changeColor_time(e){
	x=document.querySelectorAll(".time_up_down a");
	for (i=0;i<x.length;i++){
		x[i].style.color = "#303133";
	}
	e.style.color = "#F56C6C";
	time_down_up = e.getAttribute("date-index");
	var url = "/News/ajax?source="+mediaType.toString()+"&sentiment="+sentiment.toString()+"&time="+time_down_up.toString()+"&topic="+topic.toString();
	loadArticle(url);
	console.log(url);
}
function addEvent(){
	x=document.querySelectorAll(".mediaType a");
	for (i=0;i<x.length;i++){
		x[i].addEventListener("click",function(){changeColor_u(this)});
	}
	x=document.querySelectorAll(".sentiment a");
	for (i=0;i<x.length;i++){
		x[i].addEventListener("click",function(){changeColor_sentiment(this)});
	}
	x=document.querySelectorAll(".time_up_down a");
	for (i=0;i<x.length;i++){
		x[i].addEventListener("click",function(){changeColor_time(this)});
	}
}
function changeStyle(jsonStr){
	var x = document.getElementById("show_detail");
	var articles =JSON.parse(jsonStr);
//	console.log(articles[0])
	var str=`
	<table width="100%" border="" cellspacing="" cellpadding="">
		<tr style="text-align: center;">
			<th width="70%">舆情消息</th>
			<th width="10%">来源</th>
			<th width="10%">媒体类型</th>
			<th width="10%">时间</th>
		</tr>`;
	for (key in articles){
//	console.log(key)
	articles[key].pub_time = articles[key].pub_time.replace("T"," ");
	str = str + `<tr><td><h4><a href="`
	+ articles[key].url+`" target="view_window">`
	+ articles[key].title+`</a></h4><p>`
	+ articles[key].abstract+`</p><ul><span>主题词：<span>`
	+ articles[key].top_word+`</span></span><li><i class="iconfont iconlajixiang"></i></li>
	<li><i class="iconfont iconmobilephone"></i></li><li><i class="iconfont iconemail"></i></li>
	<li><i class="iconfont iconremind"></i></li><li><i class="iconfont iconlianjie"></i></li><li>
	<i class="iconfont iconbianji"></i></li><li><i class="iconfont iconjushoucang"></i></li>
	</ul></td><td style="text-align: center;">`
	+ articles[key].author+`</td><td style="text-align: center;">`
	+ articles[key].website+`</td><td style="text-align: center;">`
	+ articles[key].pub_time+`</td></tr>`
	}
	x.innerHTML=str+"</table>";
	// console.log(str);
}
function loadArticle(url){
	var xhttp = new XMLHttpRequest();
	 xhttp.onreadystatechange = function(){
		 if(this.readyState==4 && this.status==200){
			 var jsonStr = xhttp.responseText;
//			 console.log(jsonStr);
			 changeStyle(jsonStr);
		 }
	 }
	 xhttp.open("GET",url,true);
	 xhttp.send()
}